package com.example.demo.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.R;
import com.example.demo.dto.PostDto;
import com.example.demo.entity.Map;
import com.example.demo.entity.Post;
import com.example.demo.service.MapService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/map")
@Slf4j
@CrossOrigin(origins = "*", maxAge = 3600)
public class MapController {

    @Autowired
    private MapService mapService;

    /**
     * 查询所有
     *
     * @return
     */
    @GetMapping("/all")
    public R<List<Map>> all() {
        log.info("全部省份：{}");

        List<Map> aLl = mapService.getALl();

        return R.success(aLl);
    }


    /**
     * 增加人数
     *
     * @param post
     * @return
     */
    @PatchMapping
    @Transactional
    public R<String> update(@RequestBody Map map) {
        log.info("增加人数：{}", map.toString());

        mapService.updateMap(map);

        return R.success("增加成功");
    }

    /**
     * 根据ID查询省份
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<Map> getById(@PathVariable Long id) {
        log.info("根据id查询省份信息...");

        Map byId = mapService.getByID(id);

        return R.success(byId);
    }
}
